package com.alipay.app.groupmeal.standard.ui.b.function.mode;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.fastjson.JSONObject;
import com.alipay.app.groupmeal.standard.R;
import com.alipay.app.groupmeal.standard.http.RetrofitHelper;
import com.alipay.app.groupmeal.standard.http.bean.resp.Result;
import com.alipay.app.groupmeal.standard.offline.bean.OrderBean;
import com.alipay.app.groupmeal.standard.offline.manager.OrderDataManager;
import com.alipay.app.groupmeal.standard.ui.MainActivity;
import com.alipay.app.groupmeal.standard.ui.b.util.WIth;
import com.alipay.app.groupmeal.standard.ui.view.WaveProgressView;
import com.alipay.app.groupmeal.standard.widget.business.BScreenRecyclerView;
import com.alipay.app.groupmeal.standard.widget.business.BScreenTitleView;
import com.alipay.app.groupmeal.standard.widget.business.BaseBScreenView;
import com.alipay.app.groupmeal.standard.widget.business.BottomSnView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.internal.observers.BlockingBaseObserver;

/**
 * B屏统计页面
 */
public class BScreenCensus extends BaseBScreenView {
    private Display mDisplay;

    private TextView shouKuanCountTv;

    private TextView shouKuanPriceTv;

    public BScreenCensus(Context context) {
        this(context, null);
    }

    public BScreenCensus(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BScreenCensus(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_census;
    }

    @Override
    protected void initView(View view) {
        shouKuanCountTv = view.findViewById(R.id.shouKuanCountTv);
        shouKuanPriceTv = view.findViewById(R.id.shouKuanPriceTv);


    }

    @Override
    protected void initData() {

    }


    public void setData(Display display, int statusBarHeight) {
        mDisplay = display;
        try {
            new WIth(MainActivity.mActivity).getCensus(new BlockingBaseObserver<Result<JSONObject>>() {
                @Override
                public void onNext(@NonNull Result<JSONObject> jsonObjectResult) {
                    System.out.println(jsonObjectResult.getResult().toJSONString());
                    shouKuanPriceTv.setText("￥" + jsonObjectResult.getResult().getString("price"));
                    shouKuanCountTv.setText("x" + jsonObjectResult.getResult().getString("counts"));
                }

                @Override
                public void onError(@NonNull Throwable e) {

                }
            });

//            List<OrderBean> orderBeanList = OrderDataManager.getInstance().queryCensus();
//            System.out.println(orderBeanList.toString());
//
//            BigDecimal price = new BigDecimal(0);
//            for (OrderBean goo : orderBeanList) {
//                price = price.add(new BigDecimal(goo.getAmount()));
//            }

        } catch (Exception e) {
            shouKuanCountTv.setText("--");
            shouKuanPriceTv.setText("--");
        }
        show();
    }
}
